// 生成xml节点所需的配置项
Ext.require('AM.util.Ajax')

Ext.define('AM.data.OutputConfig', {


    singleton:true,


    pageConfig:function (o) {
        var config = AM.data.OutputConfig._getCommonConfig(o, ['background-image', 'background-color']);
        config['anim-name'] = o.animName;

        return config;
    },


    textConfig:function (o) {
        var config = AM.data.OutputConfig._getCommonConfig(o, ['left', 'top', 'width', 'height',
            'inner-html', 'transform', 'opacity', 'background-image', 'background-color'])

        return config;
    },


    imageConfig:function (o) {
        var config = AM.data.OutputConfig._getCommonConfig(o, ['left', 'top', 'width', 'height',
            'transform', 'opacity']);

        if (o.file != null) {
            AM.util.Ajax.uploadFile('SaveRs', o.file)
            config['image-name'] = o.file.name;
        }
        else {
            config['image-name'] = o.imageName;
        }

        return config;
    },


    audioConfig:function (o) {
        var config = AM.data.OutputConfig._getCommonConfig(o, ['left', 'top', 'width', 'height', 'transform']);
        if (o.file != null) {
            AM.util.Ajax.uploadFile('SaveRs', o.file)
            config['audio-name'] = o.file.name;
        }
        else {
            config['audio-name'] = o.audioName
        }

        return config;
    },

    _getValue:function (o, key) {
        var el = o.el;
        var dom = el.dom;
        var style = dom.style;


        switch (key) {
            case 'left':
                return style.left;
            case 'top':
                return style.top;
            case 'width':
                return style.width;
            case 'height':
                return style.height;
            case 'inner-html':
                return dom.innerHTML;
            case 'transform':
                return style.webkitTransform;
            case 'z-index':
                return style.zIndex;
            case 'src':
                return dom.src;
            case 'opacity':
                return style.opacity;
            case 'background-image':
                return style.backgroundImage;
            case 'background-color':
                return style.backgroundColor;
            case 'xtype' :
                return o.xtype;
        }
    },

    _getCommonConfig:function (o, keys) {
        var config = {};
        Ext.each(keys, function (key) {
            var value = AM.data.OutputConfig._getValue(o, key)
            if (!Ext.isEmpty(value)) {
                config[key] = AM.data.OutputConfig._getValue(o, key);
            }
        })

        return config;
    }

})